//
//  BaseTabBarViewController.m
//  预购清单
//
//  Created by  on 2022/10/15.
//

#import "BaseTabBarViewController.h"
#import "MineViewController.h"
#import "HomeViewController.h"
#import "BuyViewController.h"

@interface BaseTabBarViewController ()

@end

@implementation BaseTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addMidbtn];
}
- (void)addMidbtn{
    CGFloat height = self.tabBar.frame.size.height - [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
    UIButton * shot = [[UIButton alloc] initWithFrame:CGRectMake((self.tabBar.frame.size.width - height)*0.5, 0, height, height)];
    [shot addTarget:self action:@selector(showMidController) forControlEvents:UIControlEventTouchUpInside];
    [shot setBackgroundImage:[UIImage imageNamed:@"编辑"] forState:UIControlStateNormal];
    shot.layer.cornerRadius = height * 0.5;
    [self.tabBar addSubview:shot];
}
- (void)showMidController{
    BuyViewController *vc = [BuyViewController new];
    [[self currentVC] push:vc :NO];
}
- (void)setupColor{
    //    self.tabBar.translucent = NO;
    self.tabBar.tintColor = [@"#0041C4" color];
    self.tabBar.unselectedItemTintColor = [@"#000000" color];
    self.tabBar.backgroundImage = [UIImage withColor:[UIColor whiteColor]];
    self.tabBar.backgroundColor = [UIColor whiteColor];
}
- (void)setupViewController{
    
    NSArray *controllerArray = @[[HomeViewController new],[UIViewController new],[MineViewController new]];
    NSArray *titles = @[@"首页",@"",@"我的"];
    NSArray *imgs = @[@"首页",@"",@"我的"];
    NSArray *selectimgs = @[@"首页选中",@"",@"我的选中"];
    for (int i = 0; i < controllerArray.count; i++) {
        UIViewController *vc = controllerArray[i];
        vc.tabBarItem = [[UITabBarItem alloc] init];
        vc.tabBarItem.title = LS(titles[i]);
        vc.tabBarItem.image = [[UIImage imageNamed:imgs[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectimgs[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        vc.tabBarItem.enabled = i != 1;
        CCNavigationController *nav = [[CCNavigationController alloc] initWithRootViewController:vc];
        [self addChildViewController:nav];
    }
}
#pragma mark - UITabBarControllerDelegate
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    CCNavigationController*navc = (CCNavigationController*)viewController;
   NSString *name = NSStringFromClass([navc.visibleViewController class]);
    if ([name isEqualToString:@"UIViewController"]) {
        [self showMidController];
        return NO;
    }
    return YES;
}

@end
